package com.x.example.demo;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.x.example.page.TextProgressDrawable;
import com.x.example.page.TextProgressView;
import com.example.uiframework.utils.Utils;
import com.x.uikit.page.PageUtils;
import com.x.uikit.page.XPage;

public class TestPage extends XPage {
    boolean a = false;
    private LinearLayout mContainer;

    public TestPage(@NonNull Context context) {
        super(context);
        mContainer = new LinearLayout(context);
        this.addView(mContainer);
        mContainer.setOrientation(LinearLayout.VERTICAL);
        TextView textView = new TextView(getContext());
        textView.setBackgroundColor(0xffff0000);
        textView.setTextColor(0xff333333);
        LayoutParams lp = new LayoutParams(Utils.res.dpI(240), Utils.res.dpI(48));
        lp.gravity = Gravity.CENTER;
        mContainer.addView(textView, lp);
        textView.setText("测试");
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        textView.setGravity(Gravity.CENTER);

        textView.setOnClickListener(v -> {

            if (a) {
                PageUtils.showStatusBar(getContext());
            } else {
                PageUtils.hideStatusBar(getContext());
            }
            a = !a;
        });
        TextProgressView songTextView = new TextProgressView(getContext());
        TextProgressDrawable drawable = new TextProgressDrawable();
        drawable.setRadius(Utils.res.dpI(15));
        drawable.setBackgroundColor(0xa0A45634);
        drawable.setPadding(15);
        drawable.setProgressColor(0xffFFDCA2, 0xffFFAE3A);
        songTextView.setBackground(drawable);
        mContainer.addView(songTextView, -1, Utils.res.dpI(50));
        songTextView.setText("这个是个测试的文案");
        songTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        songTextView.setTextColor(0xff333333, 0xffffffff);
        songTextView.setProgress(progress);

        post(new Runnable() {
            @Override
            public void run() {
                progress+=0.01;
                if(progress>1){
                    progress=0;
                }
                songTextView.setProgress(progress);
                postDelayed(this,250);
            }
        });
    }
    float progress=0;
}
